<admintpl file="header"/>
</head>
<body>
<div class="wrap">
    <form method="post" class="form-horizontal " id="myform"  action="{:U('Admin/Area/editAdminPost')}">                
         <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">设置管理员</label>
            <div class="span3">
            <?php 
            	$administratored_ids_arr = array();
            	foreach($administratored_data as $administratored_key=>$administratored_value){
					if($administratored_key){
						$administratored_ids_arr[] = $administratored_key;
					}
				}
            ?>
            	<input type="hidden" name="area_id" id="area_id" value="<?php echo $area_id;?>">
            	<input type="hidden" name="administrator_hidden_ids" id="administrator_hidden_ids" value="<?php echo $administratored_ids_arr ? implode(',',$administratored_ids_arr)."," : '';?>">
                <input type="text"  style="width: 556px;" name="administrators" id="administrator" readonly="readonly" value="<?php echo $administratored_data ? implode(',',$administratored_data)."," : '';?>">
            </div>
        </div>
        
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;"></label>
            <div class="span3">
                <foreach name="administrator_data" key="administrator_key" item="administrator_value">
                <input name="administrator_checbox"  administrator_name="{$administrator_value}"  type="checkbox"   value="{$administrator_key}"  <?php if(in_array($administrator_key,$administratored_ids_arr)) echo 'checked="checked"  ';?>/>{$administrator_value}&nbsp;&nbsp;&nbsp;
                </foreach>
            </div>
        </div>
        
        
		<input type="hidden" name="area_hidden_ids" id="area_hidden_ids" value="">
        <div class="form-actions" style="padding-left:260px;">
            <a class="btn btn-primary" id="ajaxform">提 交</a>
            &nbsp;&nbsp;<a class="btn" id="ajaxback">{:L('BACK')}</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
$(function(){
	$("[name='administrator_checbox']").click(function(){
		var administrator_id = $(this).val();
		var administrator_name = $(this).attr('administrator_name');

		var administrator_hidden_ids = $("#administrator_hidden_ids").val();
		var administrator_values = $("#administrator").val();

		var ids_arr = administrator_hidden_ids.split(",");         
		var values_arr = administrator_values.split(",");   
		
		if(ids_arr.indexOf(administrator_id) == '-1'){
			administrator_hidden_ids+=administrator_id+',';
			administrator_values+=administrator_name+',';
			$("#administrator").val(administrator_values);
			$("#administrator_hidden_ids").val(administrator_hidden_ids);
		}else{
			$.each(ids_arr,function(index,item){
				 if(item==administrator_id){
					 ids_arr.splice(index,1);
					 values_arr.splice(index,1);
				 }
			}) 
			administrator_hidden_ids = ids_arr.join(",");
			administrator_values = values_arr.join(",");
			$("#administrator").val(administrator_values);
			$("#administrator_hidden_ids").val(administrator_hidden_ids);
		}
	})
})

// ajax 提交表单
$(document).ready(function(){
    $("#ajaxform").click(function(){    // 提交按钮触发事件
        var tourl = $("#myform").attr("action");    // 获取 表单的 提交地址
        var area_id = $("#area_id").val();
        var administrator_hidden_ids = $("#administrator_hidden_ids").val();
        $.post(tourl,{administrator_hidden_ids:administrator_hidden_ids,area_id:area_id},function(result){
        	if(result == '1'){
        		var msg = '编辑成功';
        	}else{
        		var msg = '编辑失败';
        	}

    		parent.layer.msg(msg,{time:2000},1,function(a){

    		});
    		setTimeout(function(){
    			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    			parent.layer.close(index);
    		}, 1000);
          });
    });
    $("#ajaxback").click(function(){
    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.layer.close(index);
    });
});
</script>
</body>
</html>